/**
 * Created by George on 2018/2/25.
 */
define(['angular', 'util'], function (angular, util) {
    "use strict";
    // 将本控制器函数作为结果返回给router.js
    var createUserCtrl = function ($scope, $http) {
        $scope.welcome_info = "会员管理";
        $scope.user = {
            name: "",
            dues: 0,
            info: "",
            joinDate: util.getNowFormatDate()
        };

        $scope.addMemberClick = function () {
            var data = {
                "name": $scope.user.name,
                "dues": $scope.user.dues,
                "info": $scope.user.info,
                "joinDate": $scope.user.joinDate
            };
            $http.post('/basketballfire/rest/user', data).then(function (req) {
                console.log("success!");
                alert("创建成功！");
                window.location.href = "/basketballfire/index.html#/user";
            }, function (req) {
                console.log("failed!");
                alert("创建失败！");
            });
        };

        function initOrUpdateData() {
            $scope.user = {
                name: "",
                dues: 0,
                info: "",
                joinDate: util.getNowFormatDate()
            };
        }

        function init() {
            initOrUpdateData();
        }

        //ctrl start
        init();
    };

    return createUserCtrl;
});